﻿using GalaSoft.MvvmLight;
using System.Windows.Input;
using System;
using GalaSoft.MvvmLight.Command;

namespace ASoft.WPF.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class ButtonViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the ButtonViewModel class.
        /// </summary>
        public ButtonViewModel()
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}
        }

        public ButtonViewModel(string content, Action execute, Func<bool> canExecute)
        {
            this._Content = content;
            this.Command = new RelayCommand(execute, canExecute);
        }

        /// <summary>
        /// The <see cref="Content" /> property's name.
        /// </summary>
        public const string ContentPropertyName = "Content";

        private string _Content = string.Empty;

        /// <summary>
        /// Gets the Content property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string Content
        {
            get
            {
                return _Content;
            }

            set
            {
                if (_Content == value)
                {
                    return;
                }

                var oldValue = _Content;
                _Content = value;
                RaisePropertyChanged(ContentPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="Command" /> property's name.
        /// </summary>
        public const string CommandPropertyName = "Command";

        private ICommand _Command = null;

        /// <summary>
        /// Gets the Command property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public ICommand Command
        {
            get
            {
                return _Command;
            }

            set
            {
                if (_Command == value)
                {
                    return;
                }

                var oldValue = _Command;
                _Command = value;
                RaisePropertyChanged(CommandPropertyName);
            }
        }
    }
}